home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / New / Copy_of_ModeProPrefs.c1 next >
Text File  |  1997-05-23  |  46KB  |  1,778 lines

  1. #define DEBUG_DELAY 50
  2. //#define DEBUG
  3. #include <debug.h>
  4. #include <extras/macros/intuition.h>
  5.  
  6. #include "MPP.h"
  7. #include <ctype.h>
  8. #include <utility/hooks.h>
  9.  
  10. long __stack = 8192;
  11.  
  12. void FixScreenModeNames(void);
  13.  
  14. extern struct LG_Control *GadControl;
  15.  
  16. BOOL MyScreen;
  17.  
  18. struct List ForcedEditList;
  19.  
  20. extern UBYTE   Version[];
  21. extern UBYTE   ModePro[];
  22. extern LONG SemVersion,
  23.             SemRevision;
  24.  
  25. ULONG  Arg_Promo, Arg_NLM, Arg_Ask, Arg_CH, Arg_CV, Arg_Debug;
  26.  
  27. UBYTE   AboutText[]="ModePro\n"
  28.                      "©1994-1997 by Michael Rivers\n"
  29.                      "  DonationWare (see Docs)\n\n"
  30.                      "%s\n"
  31.                      "%s\n"
  32.                      "  E-Mail:\n"
  33.                      "    mrivers@gte.net\n"
  34.                      "  WWW:\n"
  35.                      "    http://home1.gte.net/mrivers/\n"
  36.                      "  Mail:\n"
  37.                      "    Michael Rivers\n"
  38.                      "    4302 Wisconsin Court\n"
  39.                      "    Tampa, FL, USA, 33616";
  40.  
  41.  
  42. UBYTE EnvFile[]   ="ENV:ModePro.pref",
  43.       EnvArcFile[]="ENVARC:ModePro.pref";
  44.  
  45. ULONG ActivateStrGad=0;
  46. struct List PenList;
  47. LONG ActivePen=0;
  48. extern UBYTE PenNameGad[];
  49. struct PenNode pennode[DRIPENS];
  50. UWORD NumDriPens;
  51. UWORD defaultpens[]=
  52. {
  53.   0,1,1,2,1,3,1,0,2,1,2,1
  54. };
  55. float XScale=1.0,
  56.       YScale=1.0;
  57. extern STRPTR MiscText[];
  58. extern struct Hook StrHook,PenLVHook,StrCursorHook;
  59. //extern struct Hook MainWinHook,PaletteWinHook;
  60.  
  61. extern struct NewGadget nglist[];
  62. extern ULONG gtype[];
  63. extern ULONG gtags[];
  64. extern struct BevelBox BBox[];
  65. extern UBYTE PenNames[DRIPENS][32];
  66. extern UWORD PenNumbers[];
  67. extern struct GUI_String GText[];
  68. extern WORD PenNameLength[],
  69.             BevelBoxes;
  70. struct TextAttr *TAttr, User, SysFont;
  71. struct Menu *MenuStrip;
  72. extern struct   NewMenu nm[];      
  73. struct TextAttr Topaz8 = { "topaz.font",8,0,0};
  74.  
  75. WORD LeftEdge,TopEdge; 
  76.  
  77. struct FontRequester *FontReq;
  78. struct FileRequester *FileReq=NULL;
  79. struct ScreenModeRequester *ScrReq;
  80.  
  81. APTR VI=0;
  82. struct Gadget   *glist=0;
  83. struct Screen   *Scr=0;
  84. struct Window   *Win=0;
  85. struct DrawInfo *DrawInfo;
  86.  
  87. BOOL    V39;
  88.  
  89. UBYTE   filename[513];
  90.  
  91. LONG   LVActive=0,NodeCnt=0;
  92.  
  93. ULONG  ArgEdit,ArgUse,ArgSave;
  94. STRPTR ArgFrom,ArgPubscreen;
  95. UBYTE  *UserFontName;
  96. LONG   UserFontSize;
  97.  
  98. UBYTE *WindowName,
  99.       *WinAdd,
  100.       *Title1=" = <",
  101.       *Title2=">";
  102.  
  103. struct Catalog *Catalog;
  104.  
  105. BOOL ClosePrefs=FALSE;
  106. struct MPSem   *MPSem;
  107. struct MsgPort *PrefsPort,*ReplyPort;
  108.  
  109. struct IntuitionBase *IntuitionBase; 
  110. struct GfxBase       *GfxBase;
  111. struct Library       *AslBase,
  112.                      *CxBase,
  113.                      *DiskfontBase,
  114.                      *GadToolsBase,
  115.                      *IconBase,
  116.                      *IFFParseBase,
  117.                      *LocaleBase,
  118.                      *UtilityBase;
  119.  
  120. struct Libs MP_Libs[]=
  121. {
  122.   (APTR *)&AslBase,      "asl.library",        38,
  123.   (APTR *)&CxBase,       "commodities.library",36,
  124.   (APTR *)&DiskfontBase, "diskfont.library",   36,
  125.   (APTR *)&GadToolsBase, "gadtools.library",   36,
  126.   (APTR *)&GfxBase,      "graphics.library",   36,
  127.   (APTR *)&IconBase,     "icon.library",       36,
  128.   (APTR *)&IFFParseBase, "iffparse.library",   36,
  129.   (APTR *)&IntuitionBase,"intuition.library",  36,
  130. //  (APTR *)&LocaleBase,   "locale.library",     38,
  131.   (APTR *)&UtilityBase,  "utility.library",    36,
  132.   0,0,0
  133. };
  134.  
  135. ULONG ListToCyc[]={1,0,2,3};
  136. WORD  CurrentList_2=0,
  137.       CurrentList=1;
  138.  
  139. struct NewMenu *FindNM(struct NewMenu *Array, APTR UserData);
  140. void RefreshMenus(void);
  141. BOOL RemakeGads(void);
  142.  
  143. void SetMPSem(void);
  144.  
  145. void main(int argc, char **argv)
  146. {
  147.   ULONG l;
  148.   struct Screen *ps;
  149.   
  150.   LONG gotsem=0;
  151.  
  152.   if(LocaleBase=OpenLibrary("locale.library",38))
  153.     Catalog=OpenCatalog(NULL,(STRPTR)"modeproprefs.catalog", TAG_DONE);
  154.   else
  155.     Catalog=NULL;
  156.   
  157.   InitStrings();
  158.   NewList(&ForcedEditList);
  159.  
  160.   if(OpenLibs(ModePro,MP_Libs))
  161.   {
  162.     if(ps=LockPubScreen(NULL))
  163.     {
  164.       if(DrawInfo=GetScreenDrawInfo(ps))
  165.       {
  166.         for(l=0;l<DrawInfo->dri_NumPens && l<NumDriPens;l++)
  167.           defaultpens[l]=DrawInfo->dri_Pens[l];      
  168.         FreeScreenDrawInfo(ps,DrawInfo);
  169.       }
  170.       UnlockPubScreen(NULL,ps);
  171.     }
  172.  
  173.     if(GetArgs(argc,argv))
  174.     {
  175. //      printf("Got Args\n");
  176.       if(Scr=GetScreen())
  177.       {
  178. //        printf("Got Scr\n");
  179.         Forbid();
  180.         MPSem=(struct MPSem *)FindSemaphore((UBYTE *)"ModePro");
  181.         if(MPSem)
  182.           gotsem=AttemptSemaphoreShared(&MPSem->SharedSem);
  183.         Permit();
  184.         
  185.         if(!gotsem)
  186.         {
  187.           EZReq(0,0,ModePro,GetString(MSG_ERR_NOPATCH),GetString(MSG_REQ_OK),0);
  188.         }
  189.         else
  190.         {
  191. //          printf("Got Sem\n");
  192.        
  193.           SetMPSem();
  194.           
  195.           if(AttemptSemaphore(&MPSem->PrefsSem))
  196.           {
  197. //            printf("Got P Args\n");
  198.             if(MPSem->Version==SemVersion && MPSem->Revision==SemRevision)
  199.             {
  200. //              printf("Got Vers\n");
  201.  
  202.  
  203.               if(ArgFrom)
  204.               {
  205.                 //printf("ArgFrom = %s\n",ArgFrom);
  206.                 ObtainSemaphore(&MPSem->ListSem);
  207.                 ObtainSemaphore(&MPSem->NodeSem);
  208.                 FreeAllDefLists(MPSem->PromotionList);
  209.                 PrefLoadFile(ArgFrom);
  210.                 ReleaseSemaphore(&MPSem->NodeSem);
  211.                 ReleaseSemaphore(&MPSem->ListSem);
  212.               }
  213.               
  214.               if(ArgEdit)
  215.               {
  216.                 if(ReplyPort=CreateMsgPort())
  217.                 {
  218.                   //printf("Got RPort\n");
  219.                   if(PrefsPort=CreateMsgPort())
  220.                   {
  221.                     //printf("Got PPort\n");
  222.                     ObtainSemaphore(&MPSem->PortSem);
  223.                     MPSem->PrefsPort=PrefsPort;
  224.                     ReleaseSemaphore(&MPSem->PortSem);
  225.                     StrHook.h_Entry             =(HOOKFUNC)ExcludeHook;
  226.                     PenLVHook.h_Entry           =(HOOKFUNC)PensLVFunc;
  227.                     StrCursorHook.h_Entry       =(HOOKFUNC)PenValFunc;
  228.                     //MainWinHook.h_Entry=WinBackFillHook;
  229.                     //PaletteWinHook.h_Entry=WinBackFillHook;
  230.                
  231.                     NumDriPens=9;
  232.                     V39=FALSE;
  233.                 
  234.                     if(((struct Library *)IntuitionBase)->lib_Version>38)
  235.                     {
  236.                       NumDriPens=12;
  237.                       V39=TRUE;
  238.                     }
  239.                     
  240.                     if(WinAdd=WindowName=AllocVec(strlen(MPSem->HotKey)+
  241.                                                   strlen(GetString(MSG_WINDOW_TITLE))+
  242.                                                   strlen(Title1)+
  243.                                                   strlen(Title2)+1,MEMF_CLEAR|MEMF_PUBLIC))
  244.                     {
  245.                       strcpy(WindowName,GetString(MSG_WINDOW_TITLE));
  246.                       strcat(WindowName,Title1);
  247.                       strcat(WindowName,MPSem->HotKey);
  248.                       strcat(WindowName,Title2);
  249.                     }
  250.                     else
  251.                     {
  252.                       WindowName=ModePro; 
  253.                     }
  254.                       
  255. //                    printf("Got WinName\n");
  256.                     SetupPenNodes();
  257. //            printf("Got PenNodes\n");
  258.       
  259.                     ObtainSemaphoreShared(&MPSem->ListSem);
  260.                     FixScreenModeNames();
  261.                     
  262. //                    printf("Got ModeNames\n");
  263.                     if(GadgetInit())
  264.                     {
  265.                       if(ShowGUI())
  266.                       {
  267.                         struct Process *proc;
  268.                         struct Window *winptr;
  269.   
  270. //                            printf("Got GUI\n");
  271.                         proc=(struct Process *)FindTask(0);
  272.                         winptr=proc->pr_WindowPtr;
  273.                         proc->pr_WindowPtr=Win;
  274.                         ProcessInput();
  275.                         DKP("main() 119\n");
  276.                         proc->pr_WindowPtr=winptr;
  277.                         DKP("main() 120\n");
  278.                         HideGUI();
  279.                       }
  280.                       GadgetCleanup();
  281.                     }
  282.                     DKP("main() 200\n");
  283.                     ReleaseSemaphore(&MPSem->ListSem);
  284.                     DKP("main() 201\n");                     
  285.                     FreeVec(WinAdd);
  286.                     DKP("main() 202\n");             
  287.                     ObtainSemaphore(&MPSem->PortSem);
  288.                     DKP("main() 203\n");
  289.                     MPSem->PrefsPort=0;
  290.                     {
  291.                       struct Message *msg;
  292.                       while(msg=GetMsg(PrefsPort)
  293.                         ReplyMsg(msg);
  294.                     
  295.                       while(msg=(struct Message *)RemHead(&ForcedEditList))
  296.                         ReplyMsg(msg);
  297.                     
  298.                     }
  299.                     DKP("main() 204\n");
  300.                     ReleaseSemaphore(&MPSem->PortSem);
  301.                     DKP("main() 205\n");
  302.                     DeleteMsgPort(PrefsPort);
  303.                     DKP("main() 206\n");                    
  304.                   }// endif CreateMsgPort(PrefsPort)
  305.                   DeleteMsgPort(ReplyPort);
  306.                   DKP("main() 207\n");
  307.                 }// if CreateMsgPort(ReplyPort)
  308.               }// endif(ArgEdit)
  309.               else
  310.                 if(ArgSave)
  311.                 {
  312.                   ObtainSemaphore(&MPSem->ListSem);
  313.                   ObtainSemaphore(&MPSem->NodeSem);
  314.                   PrefSaveFile(EnvArcFile);
  315.                   PrefSaveFile(EnvFile);
  316.                   ReleaseSemaphore(&MPSem->NodeSem);            
  317.                   ReleaseSemaphore(&MPSem->ListSem);
  318.                 }
  319.             }
  320.             else
  321.               EZReq(0,0,ModePro,GetString(MSG_ERR_WRONGVERSIONS),MiscText[OK],
  322.                                          MPSem->Version,MPSem->Revision,SemVersion,SemRevision);          
  323.             ReleaseSemaphore(&MPSem->PrefsSem);
  324.           }//if(attemptsemshared()        
  325.         }//endelse (gotsem)
  326.         ReleaseScreen(Scr);
  327.       }
  328.       CleanupArgs();
  329.     }
  330.     CloseLibs(MP_Libs);
  331.   } 
  332.   if(LocaleBase)
  333.   {
  334.     CloseCatalog(Catalog);
  335.     CloseLibrary(LocaleBase);
  336.   }
  337. }
  338.  
  339. void SetMPSem(void)
  340. {
  341.   if(Arg_Promo!=5)
  342.   {
  343.     MPSem->Enabled=Arg_Promo;
  344.   }
  345.     
  346.   if(Arg_NLM!=5)
  347.   {
  348.     MPSem->EnabledNLM=Arg_NLM;
  349.   }
  350.     
  351.   if(Arg_Ask!=5)
  352.   {
  353.     MPSem->CatchScreens=Arg_Ask;
  354.   }
  355.     
  356.   if(Arg_CH!=5)
  357.   {
  358.     MPSem->CenterAll=(MPSem->CenterAll & ~1) | ( Arg_CH ? 1 : 0);
  359.   }
  360.   
  361.   if(Arg_CV!=5)
  362.   {
  363.     MPSem->CenterAll=(MPSem->CenterAll & ~2) | ( Arg_CV ? 2 : 0);
  364.   }
  365.    
  366.   if(Arg_Debug!=5)
  367.   {
  368.     MPSem->Debug=Arg_Debug;
  369.   }
  370. }
  371.  
  372.  
  373. void ProcessInput(void)
  374. {
  375.   struct IntuiMessage *imsg;
  376.   ULONG  winsig, signal, prefsig, allsigs,replysig;
  377.   
  378.   replysig= 1 << ReplyPort->mp_SigBit;
  379.   prefsig = 1 << PrefsPort->mp_SigBit; 
  380.   winsig  = 1 << Win->UserPort->mp_SigBit;  
  381.   allsigs = replysig | winsig | prefsig | SIGBREAKF_CTRL_C;
  382.   
  383.   while (!ClosePrefs)
  384.   {
  385.  
  386.     signal=Wait(allsigs);
  387.     
  388.     if(replysig & signal)
  389.     {
  390.       struct MPMessage *mpm;
  391.       while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
  392.       {
  393.         //printf("Freeing Replied Msg %8x\n",mpm);
  394.         FreeVec(mpm);
  395.       }
  396.     }
  397.     
  398.     
  399.     if(SIGBREAKF_CTRL_C & signal)
  400.       ClosePrefs=TRUE;
  401.  
  402.     if(winsig & signal)
  403.     {
  404.       while(imsg = GT_GetIMsg(Win->UserPort))
  405.       {
  406.         switch (imsg->Class)
  407.         {
  408.           case IDCMP_NEWSIZE:
  409.             if(!RemakeGads())
  410.             {
  411.               ClosePrefs=TRUE;   
  412.             }
  413.             break;
  414.           case IDCMP_MOUSEMOVE:
  415.             process_mousemoves(imsg);
  416.             break;
  417.           case IDCMP_GADGETUP:           
  418.             process_gadgetups(imsg);
  419.             break;
  420.           case IDCMP_VANILLAKEY:
  421.             Process_Keys(imsg);
  422.             break;
  423.           case IDCMP_REFRESHWINDOW:
  424.  
  425.             GT_BeginRefresh(Win);
  426.             RefreshGUI();
  427.             GT_EndRefresh(Win,TRUE);
  428.             break;
  429.           case IDCMP_MENUPICK:
  430.             process_menus(imsg);
  431.             break;            
  432.         }
  433.         GT_ReplyIMsg(imsg);
  434.       }
  435.       {
  436.         struct DefaultNode *n;
  437.         
  438.         if(n=GetActiveNode())
  439.         {
  440.           switch(ActivateStrGad)
  441.           {
  442.             /*****************************************************************************
  443.             case GD_NAME:
  444.               if(CurrentList==PL_SCREENMODES)
  445.                 ActivateStrGad=0;
  446.                 break;
  447.             ******************************************************************************/
  448.             case GD_WIDTH:
  449.             case GD_HEIGHT:
  450.               if(n->ModeSelect!=MS_PROMOTE_SCREENMODE && n->ModeSelect!=MS_PROMOTE_REQUESTER)
  451.                 ActivateStrGad=0;
  452.               break;
  453.             case GD_PENVAL:
  454.               if(!n->Look3D)
  455.                 ActivateStrGad=0;
  456.               break;
  457.             case GD_LOCKEDPENS:
  458.               if(!(n->Flags & SHAREPENS))
  459.                 ActivateStrGad=0;
  460.               break;
  461.             case GD_PUBNAME:
  462.               if(n->PubOptions==0)
  463.                 ActivateStrGad=0;
  464.               break;
  465.             case GD_HOTKEYSTR:
  466.               if(!(n->Flags & SCRHOTKEY))
  467.                 ActivateStrGad=0;
  468.               break;
  469.           }
  470.         }
  471.         else
  472.           ActivateStrGad=0;
  473.       }
  474.       if(ActivateStrGad)
  475.       {
  476.         
  477.         ActivateGadget(LG_GetGadget(GadControl,ActivateStrGad),Win,NULL);
  478.         ActivateStrGad=0;
  479.       }
  480.     }
  481.     
  482.     if(prefsig & signal)
  483.       ProcessPrefsMessages();
  484.   }
  485. }       
  486.  
  487. struct TextFont *GUIFont=0;
  488.  
  489. BOOL RemakeGads(void)
  490.                     }
  491.                     
  492.                     if(ForcedEditMsg)
  493.                       ReplyMsg(ForcedEditMsg);
  494.                     
  495.                     DKP("main() 204\n");
  496.                     ReleaseSemaphore(&MPSem->PortSem);
  497.                     DKP("main() 205\n");
  498.                     DeleteMsgPort(PrefsPort);
  499.                     DKP("main() 206\n");                    
  500.                   }// endif CreateMsgPort(PrefsPort)
  501.                   DeleteMsgPort(ReplyPort);
  502.                   DKP("main() 207\n");
  503.                 }// if CreateMsgPort(ReplyPort)
  504.               }// endif(ArgEdit)
  505.               else
  506.                 if(ArgSave)
  507.                 {
  508.                   ObtainSemaphore(&MPSem->ListSem);
  509.                   ObtainSemaphore(&MPSem->NodeSem);
  510.                   PrefSaveFile(EnvArcFile);
  511.                   PrefSaveFile(EnvFile);
  512.                   ReleaseSemaphore(&MPSem->NodeSem);            
  513.                   ReleaseSemaphore(&MPSem->ListSem);
  514.                 }
  515.             }
  516.             else
  517.               EZReq(0,0,ModePro,GetString(MSG_ERR_WRONGVERSIONS),MiscText[OK],
  518.                                          MPSem->Version,MPSem->Revision,SemVersion,SemRevision);          
  519.             ReleaseSemaphore(&MPSem->PrefsSem);
  520.           }//if(attemptsemshared()        
  521.         }//endelse (gotsem)
  522.         ReleaseScreen(Scr);
  523.       }
  524.       CleanupArgs();
  525.     }
  526.     CloseLibs(MP_Libs);
  527.   } 
  528.   if(LocaleBase)
  529.   {
  530.     CloseCatalog(Catalog);
  531.     CloseLibrary(LocaleBase);
  532.   }
  533. }
  534.  
  535. void SetMPSem(void)
  536. {
  537.   if(Arg_Promo!=5)
  538.   {
  539.     MPSem->Enabled=Arg_Promo;
  540.   }
  541.     
  542.   if(Arg_NLM!=5)
  543.   {
  544.     MPSem->EnabledNLM=Arg_NLM;
  545.   }
  546.     
  547.   if(Arg_Ask!=5)
  548.   {
  549.     MPSem->CatchScreens=Arg_Ask;
  550.   }
  551.     
  552.   if(Arg_CH!=5)
  553.   {
  554.     MPSem->CenterAll=(MPSem->CenterAll & ~1) | ( Arg_CH ? 1 : 0);
  555.   }
  556.   
  557.   if(Arg_CV!=5)
  558.   {
  559.     MPSem->CenterAll=(MPSem->CenterAll & ~2) | ( Arg_CV ? 2 : 0);
  560.   }
  561.    
  562.   if(Arg_Debug!=5)
  563.   {
  564.     MPSem->Debug=Arg_Debug;
  565.   }
  566. }
  567.  
  568.  
  569. void ProcessInput(void)
  570. {
  571.   struct IntuiMessage *imsg;
  572.   ULONG  winsig, signal, prefsig, allsigs,replysig;
  573.   
  574.   replysig= 1 << ReplyPort->mp_SigBit;
  575.   prefsig = 1 << PrefsPort->mp_SigBit; 
  576.   winsig  = 1 << Win->UserPort->mp_SigBit;  
  577.   allsigs = replysig | winsig | prefsig | SIGBREAKF_CTRL_C;
  578.   
  579.   while (!ClosePrefs)
  580.   {
  581.  
  582.     signal=Wait(allsigs);
  583.     
  584.     if(replysig & signal)
  585.     {
  586.       struct MPMessage *mpm;
  587.       while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
  588.       {
  589.         //printf("Freeing Replied Msg %8x\n",mpm);
  590.         FreeVec(mpm);
  591.       }
  592.     }
  593.     
  594.     
  595.     if(SIGBREAKF_CTRL_C & signal)
  596.       ClosePrefs=TRUE;
  597.  
  598.     if(winsig & signal)
  599.     {
  600.       while(imsg = GT_GetIMsg(Win->UserPort))
  601.       {
  602.         switch (imsg->Class)
  603.         {
  604.           case IDCMP_NEWSIZE:
  605.             if(!RemakeGads())
  606.             {
  607.               ClosePrefs=TRUE;   
  608.             }
  609.             break;
  610.           case IDCMP_MOUSEMOVE:
  611.             process_mousemoves(imsg);
  612.             break;
  613.           case IDCMP_GADGETUP:           
  614.             process_gadgetups(imsg);
  615.             break;
  616.           case IDCMP_VANILLAKEY:
  617.             Process_Keys(imsg);
  618.             break;
  619.           case IDCMP_REFRESHWINDOW:
  620.  
  621.             GT_BeginRefresh(Win);
  622.             RefreshGUI();
  623.             GT_EndRefresh(Win,TRUE);
  624.             break;
  625.           case IDCMP_MENUPICK:
  626.             process_menus(imsg);
  627.             break;            
  628.         }
  629.         GT_ReplyIMsg(imsg);
  630.       }
  631.       {
  632.         struct DefaultNode *n;
  633.         
  634.         if(n=GetActiveNode())
  635.         {
  636.           switch(ActivateStrGad)
  637.           {
  638.             /*****************************************************************************
  639.             case GD_NAME:
  640.               if(CurrentList==PL_SCREENMODES)
  641.                 ActivateStrGad=0;
  642.                 break;
  643.             ******************************************************************************/
  644.             case GD_WIDTH:
  645.             case GD_HEIGHT:
  646.               if(n->ModeSelect!=MS_PROMOTE_SCREENMODE && n->ModeSelect!=MS_PROMOTE_REQUESTER)
  647.                 ActivateStrGad=0;
  648.               break;
  649.             case GD_PENVAL:
  650.               if(!n->Look3D)
  651.                 ActivateStrGad=0;
  652.               break;
  653.             case GD_LOCKEDPENS:
  654.               if(!(n->Flags & SHAREPENS))
  655.                 ActivateStrGad=0;
  656.               break;
  657.             case GD_PUBNAME:
  658.               if(n->PubOptions==0)
  659.                 ActivateStrGad=0;
  660.               break;
  661.             case GD_HOTKEYSTR:
  662.               if(!(n->Flags & SCRHOTKEY))
  663.                 ActivateStrGad=0;
  664.               break;
  665.           }
  666.         }
  667.         else
  668.           ActivateStrGad=0;
  669.       }
  670.       if(ActivateStrGad)
  671.       {
  672.         
  673.         ActivateGadget(LG_GetGadget(GadControl,ActivateStrGad),Win,NULL);
  674.         ActivateStrGad=0;
  675.       }
  676.     }
  677.     
  678.     if(prefsig & signal)
  679.       ProcessPrefsMessages();
  680.   }
  681. }       
  682.  
  683. struct TextFont *GUIFont=0;
  684.  
  685. BOOL RemakeGads(void)
  686. {
  687.   
  688.   FreeMPPGadgets();
  689.   if(MakeMPPGadgets(Win,VI,TAttr))
  690.   {
  691.     WORD x1,x2,y1,y2;
  692.               
  693.     x1=Win->BorderLeft;
  694.     x2=Win->Width-Win->BorderRight-1;
  695.     y1=Win->BorderTop;
  696.     y2=Win->Height-Win->BorderBottom-1;
  697.     if(x1<=x2 && y1<=y2)
  698.       EraseRect(Win->RPort,x1,y1,x2,y2);
  699.     
  700.     LG_AddGadgets(Win,GadControl);
  701.     UpdateGadgets();
  702.     RefreshGUI();
  703.     RefreshWindowFrame(Win);
  704.     return(1);
  705.   }
  706.   return(0)
  707. }
  708.  
  709. extern WORD WindowWidth,WindowHeight;  
  710.  
  711. BOOL ShowGUI(void)
  712. {
  713.   WORD zoom[4];
  714.  
  715.   if(VI=GetVisualInfo(Scr,TAG_END))
  716.   {
  717.     zoom[2]=160;
  718.     zoom[3]=Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  719.     if(V39)
  720.     {
  721.       zoom[0]=zoom[1]=~0;
  722.     }
  723.     else
  724.     {
  725.       zoom[0]=0;
  726.       zoom[1]=zoom[3];
  727.     }
  728.     
  729.     if(MPSem->FirstPrefsOpen)
  730.     {
  731.       MPSem->TopEdge  =Scr->BarHeight+1;
  732.       MPSem->LeftEdge =0;
  733.       MPSem->FirstPrefsOpen=0;
  734.       MPSem->WinWidth=(WORD)(WindowWidth  * XScale);
  735.       MPSem->WinHeight=(WORD)(WindowHeight  * YScale);
  736.     }
  737.     else
  738.     {
  739.       LVActive    =MPSem->LVActive;
  740.       CurrentList =MPSem->CurrentList;
  741.       MPSem->WinWidth   =max(MPSem->WinWidth ,(WORD)(WindowWidth  * XScale));
  742.       MPSem->WinHeight  =max(MPSem->WinHeight,(WORD)(WindowHeight * YScale));
  743.     }
  744.      if(Win=OpenWindowTags(NULL, 
  745.                         WA_MaxWidth         ,~0,
  746.                         WA_MaxHeight        ,~0,
  747.                         
  748.                         TAG_SKIP            ,(MyScreen?13:0),
  749.                         WA_MinHeight        ,(LONG)(WindowHeight * YScale + Scr->WBorTop  + Scr->RastPort.TxHeight + 1 + Scr->WBorBottom) ,
  750.                         WA_InnerWidth       ,MPSem->WinWidth,
  751.                         WA_InnerHeight      ,MPSem->WinHeight,
  752.                         WA_Left             ,MPSem->LeftEdge,
  753.                         WA_Top              ,MPSem->TopEdge,
  754.                         WA_DragBar          ,TRUE,
  755.                         WA_DepthGadget      ,TRUE,
  756.                         WA_Zoom             ,zoom,
  757.                         WA_Title            ,WindowName ,
  758.                         WA_SizeGadget       ,1,
  759.                         WA_SizeBBottom      ,1,
  760.                         TAG_SKIP            ,6,
  761.                         
  762.                         WA_InnerWidth       ,(LONG)(WindowWidth  * XScale),
  763.                         WA_InnerHeight      ,(LONG)(WindowHeight  * YScale),
  764.                         WA_Backdrop         ,MyScreen,
  765.                         WA_Borderless       ,TRUE,
  766.                         WA_Left             ,0,
  767.                         WA_Top              ,Scr->BarHeight+1,
  768.                         
  769.                         WA_NewLookMenus     ,TRUE,
  770.                         WA_AutoAdjust       ,TRUE,
  771.                         WA_Activate         ,TRUE,
  772.                         WA_SimpleRefresh    ,TRUE,
  773.                         WA_IDCMP            ,MPP_IDCMP | IDCMP_NEWSIZE,
  774.                         WA_PubScreen        ,Scr  ))
  775.     {
  776.       Win->MinWidth =(WORD)(WindowWidth  * XScale + Win->BorderLeft + Win->BorderRight);
  777.       Win->MinHeight=(WORD)(WindowHeight * YScale + Win->BorderTop  + Win->BorderBottom);
  778.       SetFont(Win->RPort,GUIFont);
  779.       FindMaxPenNameSize(TAttr);
  780.       if(MakeMPPGadgets(Win,VI,TAttr))
  781.       {
  782.         LG_AddGadgets(Win,GadControl);
  783.         GT_RefreshWindow(Win,0);
  784.         //DrawBevelBoxes(Win,VI,BBox,BevelBoxes,XScale,YScale);
  785.         RefreshGUI();
  786.          {
  787.           struct NewMenu *menu;
  788.           
  789.           if(menu=FindNM(nm,(APTR)M_ENABLENL))
  790.           {
  791.             if(!V39)
  792.               menu->nm_Flags =((menu->nm_Flags | NM_ITEMDISABLED) & ~CHECKED);
  793.           }
  794.         }
  795.          if((MenuStrip=CreateMenus(nm,TAG_END))!=NULL)
  796.         {
  797.           if((LayoutMenus(MenuStrip,VI,
  798.                           GTMN_NewLookMenus,TRUE,
  799.                           TAG_END))!=NULL)
  800.           {          
  801.             if((SetMenuStrip(Win,MenuStrip))!=NULL)
  802.             {
  803.               //LVActive=0;
  804.                GT_RefreshWindow(Win,NULL);
  805.               RefreshMenus();
  806.               UpdateGadgets();
  807.               ScreenToFront(Scr);
  808.               return(TRUE);
  809.             }
  810.           }
  811.         }
  812.       }
  813.     }
  814.   }
  815.   HideGUI();
  816.   return(FALSE);
  817. }
  818.  
  819. struct NewMenu *FindNM(struct NewMenu *Array, APTR UserData)
  820. {
  821.   struct NewMenu *nm;
  822.   
  823.   nm=Array;
  824.   
  825.   while(nm->nm_UserData!=UserData && nm->nm_Type!=NM_END)
  826.     nm++;
  827.     
  828.   if(nm->nm_Type==NM_END)
  829.   {
  830.     return(0);
  831.   }
  832.   return(nm);
  833. }
  834.  
  835. void HideGUI()
  836. {
  837.   DKP("HideGUI()\n");
  838.   CleanUp();
  839.   if(Win)           
  840.   { 
  841.     MPSem->CurrentList=CurrentList;
  842.     MPSem->LVActive   =LVActive;
  843.   DKP("HideGUI() 1\n");
  844.     ClearMenuStrip(Win);
  845.   DKP("HideGUI() 2\n");
  846.     MPSem->LeftEdge=Win->LeftEdge;
  847.     MPSem->TopEdge=Win->TopEdge;
  848.     MPSem->WinWidth=GetWinInnerWidth(Win);
  849.     MPSem->WinHeight=GetWinInnerHeight(Win);
  850.   DKP("HideGUI() 3\n");
  851.     FreeMPPGadgets();
  852.   DKP("HideGUI() 5\n");
  853.     CloseWindow(Win);    
  854.   DKP("HideGUI() 6\n");
  855.     
  856.     Win=0;
  857.   }
  858.     DKP("HideGUI() 7\n");       
  859.   FreeMenus(MenuStrip);       MenuStrip=0;
  860.     DKP("HideGUI() 8\n");
  861.   FreeVisualInfo(VI);         VI=0;
  862.     DKP("HideGUI() 9\n");
  863.   
  864.   
  865.   DKP("HideGUI() 10\n");
  866.   if(GUIFont) CloseFont(GUIFont);
  867.     DKP("HideGUI() 11\n");
  868.   
  869.   /* These functions I KNOW are safe to call with a NULL */
  870.  
  871. }
  872.  
  873. struct TextAttr *WhichFont(struct Screen *Scr, struct TextAttr *TA, ... );
  874.  
  875. struct TextAttr *WhichFont(struct Screen *Scr, struct TextAttr *TA, ... )
  876. {
  877.   struct TextAttr **ta;
  878. //  struct TaxtFont *avail;
  879.   
  880.   ta=&TA;
  881.   
  882.   while(*ta)
  883.   {
  884.     if(GUIFont=OpenDiskFont(*ta))
  885.     {
  886.       GetGUIScale(*ta,GText,&XScale,&YScale);
  887.       if(CheckInnerWindowSize(Scr,WindowWidth,WindowHeight,XScale,YScale))
  888.       {
  889.         return(*ta);
  890.       }
  891.       CloseFont(GUIFont);
  892.       GUIFont=0;
  893.     }
  894.     ta++;
  895.   }
  896.   return(0);
  897. }
  898.  
  899. struct Screen *GetScreen(void)
  900. {
  901.   struct Screen *gs;
  902.   WORD pens[]={~0};
  903.   ULONG dispid;
  904.   struct TextAttr *ta;
  905.   
  906.   MyScreen=FALSE;
  907.   
  908.   if(gs=LockPubScreen(ArgPubscreen))
  909.   {
  910.     SysFont=*gs->Font;
  911.     
  912.     if(UserFontName)
  913.     {
  914.       User.ta_Name  =UserFontName;
  915.       User.ta_YSize =UserFontSize;
  916.       User.ta_Style =0;
  917.       User.ta_Flags =0;
  918.       ta=&User;
  919.     }
  920.     else
  921.       ta=&SysFont;
  922.  
  923.     if(!(TAttr=WhichFont(gs,ta,gs->Font,&Topaz8,0)))
  924.     {
  925.       TAttr=ta;
  926.       dispid=GetVPModeID(&(gs->ViewPort));
  927.       UnlockPubScreen(0,gs);
  928.       gs=0;      
  929.       GetGUIScale(TAttr,GText,&XScale,&YScale);
  930.       if(GUIFont=OpenDiskFont(TAttr))
  931.       {
  932.         MyScreen=TRUE;
  933.         gs=OpenScreenTags(0, SA_LikeWorkbench, TRUE,
  934.                              SA_Title        , ModePro,
  935.                              SA_DisplayID    , dispid,
  936.                              SA_Overscan     , OSCAN_TEXT,
  937.                              SA_AutoScroll   , TRUE,
  938.                              SA_Font         , TAttr,
  939.                              SA_Width        , (LONG)(WindowWidth  * XScale),
  940.                              SA_Height       , (LONG)(WindowHeight * YScale + TAttr->ta_YSize + 2),
  941.                              SA_Depth        , 2,
  942.                              SA_Pens         , pens,
  943.                              TAG_DONE);
  944.       }
  945.     }
  946.   }
  947.   if(gs)
  948.   {
  949.     if(DrawInfo=GetScreenDrawInfo(gs))
  950.     {
  951.     //  MainWinHook.h_Data=DrawInfo->dri_Pens[BACKGROUNDPEN];
  952.     }
  953.   }
  954.   else
  955.   {
  956.     if(GUIFont)
  957.       CloseFont(GUIFont);
  958.   }
  959.   return(gs);
  960. }
  961.  
  962. void ReleaseScreen(struct Screen *S)
  963. {
  964.   if(S)
  965.   {
  966.     FreeScreenDrawInfo(S,DrawInfo);
  967.     if(MyScreen)
  968.       CloseScreen(S);
  969.     else
  970.       UnlockPubScreen(0,S);
  971.   }
  972.   if(GUIFont)
  973.     CloseFont(GUIFont);
  974. }
  975.  
  976. void CleanUp(void)
  977. {
  978.   if(ScrReq)
  979.   {
  980.     FreeAslRequest(ScrReq);
  981.     ScrReq=0;
  982.   }
  983.   if(FileReq)
  984.   {
  985.     FreeAslRequest(FileReq);
  986.     FileReq=0;
  987.   }
  988.   if(FontReq)
  989.   {
  990.     FreeAslRequest(FontReq);
  991.     FontReq=0;
  992.   }
  993. }
  994.  
  995. void CheckMenuItem(ULONG MenuItem, BOOL Checked);
  996.  
  997. void ProcessPrefsMessages(void)
  998. {
  999.   ULONG listupd=FALSE;
  1000.   struct MPMessage *mpm;
  1001.  
  1002. loopy:
  1003.  
  1004.   while(mpm=(struct MPMessage *)GetMsg(PrefsPort))
  1005.   {
  1006.     //printf("Recieved %8x - Command %d Code %d Data %8x\n",mpm,mpm->Command,mpm->Code,mpm->Data);   
  1007.     switch(mpm->Command)
  1008.     {
  1009.       case MP_FORCEDEDIT:
  1010.         ForcedEditMsg=mpm;
  1011.         RemakeGads();
  1012.         mpm=0;
  1013.         break;
  1014.       case MP_QUIT:
  1015.       case MP_PREFSCLOSE:
  1016.         ClosePrefs=TRUE;
  1017.         break;
  1018.       case MP_PREFSTOFRONT:
  1019.         ScreenToFront(Scr);
  1020.         WindowToFront(Win);
  1021.         ActivateWindow(Win);
  1022.         break;
  1023.       case MP_LISTSTATUS:
  1024.         switch(mpm->Code)
  1025.         {
  1026.           case MPLS_UPDATING:
  1027.             listupd=TRUE;
  1028.             LG_SetGadgetAttrs(GadControl,GD_LIST,
  1029.                          GTLV_Labels,~0,
  1030.                          TAG_DONE);
  1031.             
  1032.             ReleaseSemaphore(&MPSem->ListSem);
  1033.             break;
  1034.           case MPLS_NORMAL:
  1035.             listupd=FALSE;          
  1036.             ObtainSemaphoreShared(&MPSem->ListSem);
  1037.             LVActive=0;
  1038.             UpdateGadgets();
  1039.             break;
  1040.         }
  1041.         break;
  1042.       case MP_REFRESH:
  1043.         RefreshMenus();
  1044.         break;
  1045.       case MP_NEWNODE:
  1046.         GD_Type(ListToCyc[mpm->Code]);  // change to the correct list
  1047.         break;
  1048.       
  1049.     }
  1050.     if(mpm)
  1051.       ReplyMsg((struct Message *)mpm);
  1052.   }
  1053.   if(listupd)
  1054.   {
  1055.     WaitPort(PrefsPort);
  1056.     goto loopy;
  1057.   }
  1058. }
  1059.  
  1060. void RefreshMenus(void)
  1061. {
  1062.   CheckMenuItem(M_ENABLED     ,MPSem->Enabled);
  1063.   CheckMenuItem(M_ENABLENL    ,MPSem->EnabledNLM);  
  1064.   CheckMenuItem(M_SET_UNKNOWN ,MPSem->CatchScreens);
  1065.   CheckMenuItem(M_SET_CENTER_H,MPSem->CenterAll & 1);
  1066.   CheckMenuItem(M_SET_CENTER_V,MPSem->CenterAll & 2);
  1067.   ResetMenuStrip(Win,MenuStrip);
  1068. }
  1069.  
  1070. void CheckMenuItem(ULONG MenuItem, BOOL Checked)
  1071. {
  1072.   struct MenuItem *mi;
  1073.   
  1074.   if(mi=ItemAddress(MenuStrip,MenuItem))
  1075.   {
  1076.     if(Checked)
  1077.       mi->Flags|=CHECKED;
  1078.     else
  1079.       mi->Flags&=(~CHECKED);
  1080.   }
  1081. }
  1082.     
  1083. void process_gadgetups(struct IntuiMessage *imsg)
  1084. {
  1085.   struct Gadget *gad;
  1086.   struct DefaultNode *n;
  1087.   UWORD  code,id;  
  1088.   
  1089.   code=imsg->Code;
  1090.   gad=(struct Gadget*)imsg->IAddress;
  1091.   id=gad->GadgetID;  
  1092.    
  1093.   switch(id)
  1094.   {
  1095.  
  1096.     case GD_NEW:
  1097.       GD_New();
  1098.       break;
  1099.  
  1100.     case GD_SAVE:
  1101.       GD_Save();
  1102.       break;
  1103.     case GD_USE:
  1104.       GD_Use();
  1105.       break;
  1106.     case GD_CANCEL:
  1107.       GD_Cancel();
  1108.       break;
  1109.       
  1110.     case GD_TYPE:
  1111.       GD_Type(code);
  1112.       break;
  1113.   }
  1114.  
  1115.   if(n=GetActiveNode())  
  1116.   switch(id)
  1117.   {
  1118.     case GD_LIST:
  1119.       GD_List(code,0);
  1120.       break;
  1121.       
  1122.     case GD_SELECT_NAME:
  1123.       GD_SelectName(n);
  1124.       break;
  1125.  
  1126.     case GD_NAME:
  1127.       LG_SetGadgetAttrs(GadControl,GD_LIST,
  1128.                          GTLV_Labels,~0,TAG_DONE);
  1129.       if(GetGadString(LG_GetGadget(GadControl,GD_NAME)))
  1130.       {
  1131.         STRPTR oldname;
  1132.         ObtainSemaphore(&MPSem->NodeSem);
  1133.         oldname=n->Def_Node.ln_Name;
  1134.         if(n->Def_Node.ln_Name=AllocVec( 1+strlen(GetGadString(LG_GetGadget(GadControl,GD_NAME))),MEMF_CLEAR|MEMF_PUBLIC))
  1135.         {
  1136. /***************************************************************************************************************************/
  1137.           n->OrigDisplayID=INVALID_ID;
  1138. /***************************************************************************************************************************/
  1139.           strcpy(n->Def_Node.ln_Name,GetGadString(LG_GetGadget(GadControl,GD_NAME)));
  1140.           FreeVec(oldname);
  1141.         }
  1142.         else
  1143.         {
  1144.           //Remove((struct Node *)n);
  1145.           //FreeDNode(n);
  1146.           n->Def_Node.ln_Name=oldname;
  1147.       //    UpdateGadgets();
  1148.         }
  1149.         ReleaseSemaphore(&MPSem->NodeSem);
  1150.       }
  1151.      
  1152.       LG_SetGadgetAttrs(GadControl,GD_LIST,
  1153.                          GTLV_Labels,&MPSem->PromotionList[CurrentList],
  1154.                          TAG_DONE);
  1155.                          
  1156.       if(imsg->Qualifier&3)
  1157.       {//shifted
  1158.         switch(code)
  1159.         {
  1160.           case CURSORUP:
  1161.             GD_Move((NodeCnt-LVActive-1)+1);
  1162.             LG_SetGadgetAttrs(GadControl,GD_MOVE,
  1163.                       GTSL_Level,       (NodeCnt-1)-LVActive,
  1164.                       TAG_DONE);
  1165.             ActivateStrGad=GD_NAME;   
  1166.             break;
  1167.           case CURSORDOWN:
  1168.             GD_Move((NodeCnt-LVActive-1)-1);
  1169.             LG_SetGadgetAttrs(GadControl,GD_MOVE,
  1170.                       GTSL_Level,       (NodeCnt-1)-LVActive,
  1171.                       TAG_DONE);
  1172.             ActivateStrGad=GD_NAME;
  1173.             break;
  1174.         }
  1175.       }
  1176.       else
  1177.       {
  1178.         switch(code)
  1179.         {
  1180.           case CURSORUP:
  1181.             LVActive-=2;
  1182.           case CURSORDOWN:
  1183.             LVActive++;
  1184.             GD_List(LVActive,0);
  1185.             LG_SetGadgetAttrs(GadControl,GD_LIST,
  1186.                               GTLV_Selected       ,LVActive,
  1187.                               TAG_DONE);
  1188.             break;
  1189.         }        
  1190.       }
  1191.       break;
  1192.       
  1193.     case GD_MODESEL:
  1194.       GD_ModeSel(n,code,0);
  1195.       break;
  1196.  
  1197.     case GD_SELMODE:
  1198.       GD_SelMode(n);
  1199.       break;
  1200.  
  1201.     case GD_WIDTH:
  1202.       n->Width=GetGadNumber(gad);
  1203.       break;
  1204.  
  1205.     case GD_HEIGHT:
  1206.       n->Height=GetGadNumber(gad);
  1207.       break;
  1208.  
  1209.     case GD_OVERSCAN:
  1210.       GD_Overscan(n,code,FALSE);
  1211.       break;
  1212.  
  1213.     case GD_REMOVE:
  1214.       GD_Remove(n);
  1215.       break;
  1216.  
  1217.     case GD_LOOK3D:
  1218.       GD_Look3D(n,gad->Flags & GFLG_SELECTED);
  1219.       break;
  1220.  
  1221.     case GD_AUTOSCROLL:
  1222.       GD_AutoScroll(n,gad->Flags & GFLG_SELECTED,FALSE);
  1223.       break;
  1224.  
  1225.     case GD_3D_DEFAULT:
  1226.       GD_3D_Default(n,gad->Flags & GFLG_SELECTED,FALSE);
  1227.       break;
  1228.  
  1229.     case GD_PENLIST:
  1230.       GD_PenList(n,code);
  1231.       break;
  1232.  
  1233.     case GD_PENVAL:
  1234.       n->Pens[ActivePen]=GetGadNumber(LG_GetGadget(GadControl,GD_PENVAL));
  1235.       switch(code)
  1236.       {
  1237.         
  1238.         case CURSORUP:
  1239.           ActivateStrGad=GD_PENVAL;
  1240.           ActivePen--;
  1241.           if(ActivePen<0)
  1242.             ActivePen=NumDriPens-1;
  1243.           break;
  1244.         case CURSORDOWN:
  1245.           ActivateStrGad=GD_PENVAL;
  1246.           ActivePen++;
  1247.           if(ActivePen>=NumDriPens)
  1248.             ActivePen=0;
  1249.           break;
  1250.       }
  1251.       //      if(imsg->Qualifier&3)
  1252.       SetPenValues(n->Pens);
  1253.       break;
  1254.  
  1255.     case GD_RESETPENS:
  1256.       GD_ResetPens(n);
  1257.       break;
  1258.  
  1259.     case GD_PICKFONT:
  1260.       GD_PickFont(n);
  1261.       break;
  1262.  
  1263.     case GD_INTERLEAVE:
  1264.       GD_Interleave(n,gad->Flags & GFLG_SELECTED,FALSE);
  1265.       break;
  1266.  
  1267.     case GD_BEHIND:
  1268.       GD_Behind(n,gad->Flags & GFLG_SELECTED,FALSE);
  1269.       break;
  1270.     
  1271.     case GD_BLANK_BORDER:
  1272.       GD_Blank_Border(n,gad->Flags & GFLG_SELECTED,FALSE);
  1273.       break;
  1274.       
  1275.     case GD_CENTER:
  1276.       n->CenterFlags=code;
  1277.       break;
  1278.  
  1279.     case GD_FASPECT:
  1280.       GD_FAspect(n,gad->Flags & GFLG_SELECTED,FALSE);
  1281.       break;
  1282.  
  1283.     case GD_SFONT:
  1284.       GD_SFont(n,code);
  1285.       break;
  1286.  
  1287.     case GD_PUBOPT:
  1288.       GD_PubOpt(n,gad->Flags & GFLG_SELECTED,FALSE);
  1289.       break;
  1290.       
  1291.     case GD_PUBNAME:
  1292.       if(GetGadString(LG_GetGadget(GadControl,GD_PUBNAME)))
  1293.       {
  1294.         ObtainSemaphore(&MPSem->NodeSem);
  1295.         FreeVec(n->PubName);
  1296.         if(n->PubName=AllocVec( 1+strlen(GetGadString(LG_GetGadget(GadControl,GD_PUBNAME))),MEMF_CLEAR|MEMF_PUBLIC))
  1297.           strcpy(n->PubName,GetGadString(LG_GetGadget(GadControl,GD_PUBNAME)));
  1298.         ReleaseSemaphore(&MPSem->NodeSem);
  1299.       }      
  1300.       break;
  1301.       
  1302.     case GD_DODEPTH:
  1303.       GD_DoDepth(n,gad->Flags & GFLG_SELECTED);
  1304.       break;
  1305.       
  1306.     case GD_SHAREPENS:
  1307.       GD_SharePens(n,gad->Flags & GFLG_SELECTED,FALSE);
  1308.       break;
  1309.       
  1310.     case GD_LOCKEDPENS:
  1311.       if(GetGadString(LG_GetGadget(GadControl,GD_LOCKEDPENS)))
  1312.       {
  1313.         ObtainSemaphore(&MPSem->NodeSem);
  1314.         FreeVec(n->LockedPens);
  1315.         if(n->LockedPens=AllocVec( 1+strlen(GetGadString(LG_GetGadget(GadControl,GD_LOCKEDPENS))),MEMF_CLEAR|MEMF_PUBLIC))
  1316.           strcpy(n->LockedPens,GetGadString(LG_GetGadget(GadControl,GD_LOCKEDPENS)));
  1317.         ReleaseSemaphore(&MPSem->NodeSem);
  1318.       }      
  1319.       break;
  1320.     
  1321.     case GD_HOTKEYOPT:
  1322.       GD_HotKeyOpt(n,gad->Flags & GFLG_SELECTED,FALSE);
  1323.       break;
  1324.       
  1325.     case GD_HOTKEYSTR:
  1326.       if(GetGadString(LG_GetGadget(GadControl,GD_HOTKEYSTR)))
  1327.       {
  1328.         ObtainSemaphore(&MPSem->NodeSem);
  1329.         FreeVec(n->HotKey);
  1330.         if(n->HotKey=AllocVec( 1+strlen(GetGadString(LG_GetGadget(GadControl,GD_HOTKEYSTR))),MEMF_CLEAR|MEMF_PUBLIC))
  1331.           strcpy(n->HotKey,GetGadString(LG_GetGadget(GadControl,GD_HOTKEYSTR)));
  1332.         ReleaseSemaphore(&MPSem->NodeSem);
  1333.       }
  1334.       break;
  1335.     case GD_PALETTE:
  1336.       GD_Palette(n,gad->Flags & GFLG_SELECTED);
  1337.       break;
  1338.       
  1339.     case GD_EDITPALETTE:
  1340.       GD_EditPalette(n);
  1341.       break;
  1342.       
  1343.     case GD_FORCE_PLANAR:
  1344.       GD_Force_Planar(n,gad->Flags & GFLG_SELECTED,FALSE);
  1345.       break;
  1346.   } /* End Switch */  
  1347. }
  1348.  
  1349. void Process_Keys(struct IntuiMessage *IMsg)
  1350. {
  1351.   ULONG code,gadid;
  1352.   WORD dirchange=1;
  1353.   WORD letter;
  1354.   struct DefaultNode *n;
  1355.   
  1356.   letter=IMsg->Code;
  1357.  
  1358.   if(LG_GadForKey(GadControl,letter,&gadid,&code))  
  1359.   {
  1360.     if(code&1) dirchange=-1;
  1361.     switch(gadid)
  1362.     {
  1363.       case GD_LIST:
  1364.         gadid=GD_NAME;
  1365.       case GD_NAME:
  1366.       case GD_WIDTH:
  1367.       case GD_HEIGHT:
  1368.       case GD_LOCKEDPENS:
  1369.       case GD_PUBNAME:
  1370.       case GD_HOTKEYSTR:
  1371.       case GD_PENVAL:
  1372.         ActivateStrGad=gadid;
  1373.         break;
  1374.       case GD_TYPE:
  1375.         CurrentList_2+=dirchange;
  1376.         GD_Type(CurrentList_2);
  1377.         break;
  1378.       case GD_NEW:
  1379.         GD_New();
  1380.         break;
  1381.       case GD_SAVE:
  1382.         GD_Save();
  1383.         break;
  1384.       case GD_USE:
  1385.         GD_Use();
  1386.         break;
  1387.       case GD_CANCEL:
  1388.         GD_Cancel();
  1389.         break;
  1390.     }
  1391.     if(n=GetActiveNode())
  1392.     switch(gadid)
  1393.     {
  1394.       case GD_SELECT_NAME:
  1395.         GD_SelectName(n);
  1396.         break;
  1397.       case GD_MODESEL:
  1398.         GD_ModeSel(n,n->ModeSelect+dirchange,1);
  1399.         break;
  1400.       case GD_SELMODE:
  1401.         GD_SelMode(n);
  1402.         break;
  1403.       case GD_OVERSCAN: 
  1404.         GD_Overscan(n,n->OverscanType+dirchange-1,TRUE);
  1405.         break;
  1406.       case GD_REMOVE:
  1407.         GD_Remove(n);
  1408.         break;
  1409.       case GD_PENLIST:
  1410.         GD_PenList(n,ActivePen+dirchange);
  1411.         break;
  1412.       case GD_RESETPENS:
  1413.         GD_ResetPens(n);
  1414.         break;
  1415.       case GD_PICKFONT:
  1416.         GD_PickFont(n);
  1417.         break;
  1418.       case GD_INTERLEAVE:
  1419.         GD_Interleave(n,!(n->Flags & INTERLEAVE),TRUE);
  1420.         break;
  1421.       case GD_BEHIND:
  1422.         GD_Behind(n,!(n->Flags & DNF_BEHIND),TRUE);
  1423.         break;
  1424.       case GD_BLANK_BORDER:
  1425.         GD_Blank_Border(n,!(n->Flags & DNF_BLANK_BORDER),TRUE);
  1426.         break;
  1427.       case GD_LOOK3D:
  1428.         GD_Look3D(n,!(n->Look3D));
  1429.         break;
  1430.       case GD_AUTOSCROLL:
  1431.         GD_AutoScroll(n,!(n->AutoScroll),TRUE);
  1432.         break;
  1433.       case GD_3D_DEFAULT:
  1434.         GD_3D_Default(n,!(n->Flags & DNF_3D_DEFAULT),TRUE);
  1435.         break;
  1436.       case GD_CENTER:
  1437.         GD_Center(n,n->CenterFlags+dirchange,TRUE);
  1438.         break;
  1439.       case GD_FASPECT:
  1440.         GD_FAspect(n,!(n->Flags & FIXASPECT),TRUE);
  1441.         break;
  1442.       case GD_SFONT:
  1443.         GD_SFont(n,n->FontType+dirchange);
  1444.         break;
  1445.       case GD_PUBOPT:
  1446.         GD_PubOpt(n,!(n->PubOptions),TRUE);
  1447.         break;
  1448.       case GD_DODEPTH:
  1449.         GD_DoDepth(n,!(n->Flags & DEPTH));
  1450.         break;
  1451.       case GD_SHAREPENS:
  1452.         GD_SharePens(n,!(n->Flags & SHAREPENS),TRUE);
  1453.         break;
  1454.       case GD_HOTKEYOPT:
  1455.         GD_HotKeyOpt(n,!(n->Flags & SCRHOTKEY),TRUE);
  1456.         break;
  1457.       case GD_PALETTE:
  1458.         GD_Palette(n,!(n->Flags & DNF_PALETTE));
  1459.         break;
  1460.       case GD_EDITPALETTE:
  1461.         GD_EditPalette(n);
  1462.         break;
  1463.       case GD_MOVE:
  1464.         GD_Move(LVActive+dirchange);
  1465.         break;
  1466.       case GD_DEPTH:
  1467.         GD_Depth(n,n->Depth-dirchange,TRUE);
  1468.         break;
  1469.       case GD_FORCE_PLANAR:
  1470.         GD_Force_Planar(n,!(n->Flags & DNF_FORCEPLANAR),TRUE);
  1471.         break;
  1472.     }
  1473.   }
  1474. }
  1475.  
  1476.  
  1477. void process_mousemoves(struct IntuiMessage *imsg)
  1478. {
  1479.   struct Gadget *gad;
  1480.   struct DefaultNode *n;
  1481.   UWORD  code,id;  
  1482.   
  1483.   code=imsg->Code;
  1484.   gad=(struct Gadget*)imsg->IAddress;
  1485.   id=gad->GadgetID;
  1486.   if(n=GetActiveNode())
  1487.   {
  1488.     switch(id)
  1489.     {
  1490.       case GD_MOVE:
  1491.         GD_Move(code);
  1492.         break;
  1493.       case GD_DEPTH:
  1494.         GD_Depth(n,code,FALSE);
  1495.         break;
  1496.     } /* End Switch */
  1497.   }  
  1498. }
  1499.  
  1500.  
  1501. void process_menus(struct IntuiMessage *imsg)
  1502. {
  1503.   UWORD  menunumber,ns;
  1504.   ULONG  menuid;
  1505.   struct MenuItem *mi;
  1506.   
  1507.   menunumber=imsg->Code;
  1508.   mi=ItemAddress(MenuStrip,menunumber);
  1509.   if(mi)
  1510.   do
  1511.   {
  1512.     menuid=(ULONG)(GTMENUITEM_USERDATA(mi));
  1513.     switch(menuid)
  1514.     {
  1515.       case M_OPEN:
  1516.         if(SelectFile(MiscText[LOAD_MP_PREFS],FALSE) )
  1517.         {
  1518.            ObtainSemaphore(&MPSem->NodeSem);
  1519.            LG_SetGadgetAttrs(GadControl,GD_LIST,
  1520.                          GTLV_Labels,~0,TAG_DONE);
  1521.            FreeAllDefLists(MPSem->PromotionList);
  1522.            ReleaseSemaphore(&MPSem->NodeSem);
  1523.            PrefLoadFile(filename);
  1524.  
  1525.            LVActive=0;
  1526.            UpdateGadgets();
  1527.         }
  1528.         break;
  1529.         /*
  1530.       case M_SAVE:
  1531.         ObtainSemaphore(&MPSem->NodeSem);
  1532.         PrefSaveFile(EnvArcFile);
  1533.         PrefSaveFile(EnvFile);
  1534.         ReleaseSemaphore(&MPSem->NodeSem);
  1535.         break;
  1536.         */
  1537.       case M_SAVEAS:
  1538.         if(SelectFile(MiscText[SAVE_MP_PREFS],TRUE) )
  1539.         {
  1540.           PrefSaveFile(filename);     
  1541.         }
  1542.         break;
  1543.       case M_ENABLED:
  1544.         MPSem->Enabled=(mi->Flags & CHECKED ? 1:0);
  1545.         //ActivateCxObj(Broker,MPSem->Enabled);
  1546.         break;
  1547.       case M_ABOUT:
  1548.         {
  1549.           EZReq(Win,0,ModePro,AboutText,MiscText[OK],(ULONG)GetString(MSG_ABOUT_TRANSLATOR),
  1550.                                                     (ULONG)GetString(MSG_ABOUT_FORINFO));
  1551.         }
  1552.         break;
  1553.       case M_HIDE:
  1554.         ClosePrefs=TRUE;
  1555.         //PrefSaveFile(EnvFile);
  1556.         break;
  1557.       case M_LASTSAVED:
  1558.         ObtainSemaphore(&MPSem->NodeSem);
  1559.         LG_SetGadgetAttrs(GadControl,GD_LIST,
  1560.                                  GTLV_Labels,~0,TAG_DONE);
  1561.         FreeAllDefLists(MPSem->PromotionList);
  1562.         ReleaseSemaphore(&MPSem->NodeSem);
  1563.         PrefLoadFile(EnvArcFile);
  1564.         LVActive=0;
  1565.         UpdateGadgets();
  1566.         break;   
  1567.       case M_RESTORE:
  1568.         ObtainSemaphore(&MPSem->NodeSem);
  1569.         LG_SetGadgetAttrs(GadControl,GD_LIST,
  1570.                                  GTLV_Labels,~0,TAG_DONE);
  1571.         FreeAllDefLists(MPSem->PromotionList);
  1572.         ReleaseSemaphore(&MPSem->NodeSem);
  1573.         PrefLoadFile(EnvFile);
  1574.         LVActive=0;
  1575.         UpdateGadgets();
  1576.         break;   
  1577.       case M_QUIT:
  1578.         SendDaemonMsg(MP_QUIT,0,0);
  1579.         break;
  1580.       case M_ENABLENL:
  1581.         MPSem->EnabledNLM=(mi->Flags & CHECKED ? 1:0);
  1582.         break;
  1583.       case M_SET_UNKNOWN:
  1584.         MPSem->CatchScreens=(mi->Flags & CHECKED ? 1:0);
  1585.         break;
  1586.       case M_SET_CENTER_H:
  1587.         MPSem->CenterAll=(MPSem->CenterAll & ~1) | (mi->Flags & CHECKED ? 1:0);
  1588.         break;
  1589.       case M_SET_CENTER_V:
  1590.         MPSem->CenterAll=(MPSem->CenterAll & ~2) | (mi->Flags & CHECKED ? 2:0);
  1591.         break;
  1592.       case M_COPY_TO_SCR:
  1593.       case M_COPY_TO_PRG:
  1594.       case M_COPY_TO_PUB:
  1595.         if(CurrentList != PL_SCREENMODES)
  1596.         {
  1597.           struct DefaultNode *dnode; 
  1598.  
  1599.           if(dnode=DupDNode(GetActiveNode()))  
  1600.           {
  1601.             switch(menuid)
  1602.             {
  1603.               case M_COPY_TO_SCR:
  1604.                 dnode->Type=PL_SCREENNAMES;
  1605.                 break;
  1606.               case M_COPY_TO_PRG:
  1607.                 dnode->Type=PL_PROGRAMNAMES;
  1608.                 break;
  1609.               case M_COPY_TO_PUB:
  1610.                 dnode->Type=PL_PUBLICSCREENS;
  1611.                 break;
  1612.             }
  1613.             ObtainSemaphore(&MPSem->NodeSem);
  1614.             LG_SetGadgetAttrs(GadControl,GD_LIST,
  1615.                               GTLV_Labels      ,~0,
  1616.                               GTLV_Selected    ,0,
  1617.                               TAG_DONE);
  1618.             AddHead(&MPSem->PromotionList[dnode->Type],(struct Node *)dnode);
  1619.             ReleaseSemaphore(&MPSem->NodeSem);
  1620.             GD_Type(dnode->Type);
  1621.           }
  1622.         }
  1623.         break;
  1624.     }
  1625.     ns=mi->NextSelect;
  1626.     mi=ItemAddress(MenuStrip,mi->NextSelect);
  1627.   }while(ns!= MENUNULL && mi);
  1628. }
  1629.  
  1630. void SetupPenNodes(void)
  1631. {
  1632.   ULONG pen;
  1633.   
  1634.   NewList(&PenList);
  1635.   for(pen=0;pen<NumDriPens;pen++)
  1636.   {
  1637. //    printf("%d\n",pen);
  1638.     pennode[pen].PenNumber       =PenNumbers[pen];
  1639.     pennode[pen].Pen_Node.ln_Name=PenNames[pen];
  1640.     pennode[pen].Pen_Node.ln_Succ=pennode[pen].Pen_Node.ln_Pred=0;
  1641.     AddTail(&PenList,(struct Node *)&pennode[pen]);
  1642.   }  
  1643. }
  1644.  
  1645. void SetPenValues(WORD *pens)
  1646. {
  1647.   ULONG pen,maxlenpng;
  1648.  
  1649.  
  1650.   LG_SetGadgetAttrs(GadControl,GD_PENLIST,
  1651.                     GTLV_Labels,~0,TAG_DONE);  
  1652.   if(pens)
  1653.   {
  1654.     for(pen=0;pen<NumDriPens;pen++)
  1655.     {
  1656.       stci_d(&PenNames[pen][PenNameLength[pen]],pens[pen]);
  1657.     }
  1658.     
  1659.     LG_SetGadgetAttrs(GadControl,GD_PENVAL,
  1660.                          GA_Disabled  ,FALSE,
  1661.                          GTIN_Number  ,pens[ActivePen],
  1662.                          TAG_DONE);
  1663.     LG_SetGadgetAttrs(GadControl,GD_RESETPENS,
  1664.                          GA_Disabled  ,FALSE,
  1665.                          TAG_DONE);
  1666.   }
  1667.   else
  1668.   {
  1669.     for(pen=0;pen<NumDriPens;pen++)
  1670.     {
  1671.       PenNames[pen][PenNameLength[pen]]=0;
  1672.     }
  1673.     LG_SetGadgetAttrs(GadControl,GD_PENVAL,
  1674.                          GA_Disabled  ,TRUE,
  1675.                          TAG_DONE);
  1676.     LG_SetGadgetAttrs(GadControl,GD_RESETPENS,
  1677.                          GA_Disabled  ,TRUE,
  1678.                          TAG_DONE);
  1679.  
  1680.   }
  1681.   LG_SetGadgetAttrs(GadControl,GD_PENLIST,
  1682.                          GTLV_Labels      ,&PenList,
  1683.                          GTLV_MakeVisible ,ActivePen,
  1684.                          GTLV_Selected    ,ActivePen,
  1685.                          GA_Disabled      ,!pens,
  1686.                          TAG_DONE);
  1687.   //LG_SetGadgetAttrs(GadControl,GD_PENNAME,
  1688.   //                       GTTX_Text,NULL,TAG_DONE);
  1689.   
  1690.   
  1691.   maxlenpng=min(31,PenNameLength[ActivePen]);
  1692.   strncpy(PenNameGad,PenNames[ActivePen],maxlenpng);
  1693.   PenNameGad[maxlenpng]=0;
  1694.   //LG_SetGadgetAttrs(GadControl,GD_PENNAME,
  1695.   //                       GTTX_Text,PenNameGad,TAG_DONE);
  1696.   WritePenNameDisp(PenNameGad);
  1697. }    
  1698.  
  1699. LONG SendDaemonMsg(ULONG Command, ULONG Code, APTR Data)
  1700. {
  1701.   LONG rv=0;
  1702.   struct MPMessage *mpm;
  1703.  
  1704.   if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
  1705.   {
  1706.     mpm->Command=Command;
  1707.     mpm->Code=Code;
  1708.     mpm->Data=Data;
  1709.     mpm->mp_Message.mn_ReplyPort=ReplyPort;
  1710.  
  1711.     //printf("Sending  %8x - Command %d Code %d Data %8x\n",mpm,mpm->Command,mpm->Code,mpm->Data);   
  1712.     PutMsg(MPSem->DaemonPort,(struct Message *)mpm);
  1713.     rv=1;
  1714.   }
  1715.  
  1716.   return(rv);
  1717. }
  1718.  
  1719. BOOL PrefLoadFile(STRPTR FileName)
  1720. {
  1721.   LONG error;
  1722.   BOOL rv;
  1723.   
  1724.   ObtainSemaphore(&MPSem->NodeSem);
  1725.   rv=LoadFile(MPSem->PromotionList,FileName);
  1726.   FixScreenModeNames();
  1727.   ReleaseSemaphore(&MPSem->NodeSem);
  1728.   if(error=IoErr())
  1729.   {
  1730.     UBYTE errstr[91];
  1731.  
  1732.     Fault(error,MiscText[LOAD_ERROR],errstr,90);
  1733.     EZReq(Win,0,ModePro,errstr,MiscText[OK],0);
  1734.   }
  1735.   RefreshMenus();
  1736.   return(rv);
  1737. }    
  1738.  
  1739.  
  1740. BOOL PrefSaveFile(STRPTR FileName)
  1741. {
  1742.   LONG error;
  1743.   BOOL rv;
  1744.   
  1745.   ObtainSemaphore(&MPSem->NodeSem);
  1746.   rv=SaveFile(MPSem->PromotionList,FileName);
  1747.   ReleaseSemaphore(&MPSem->NodeSem);
  1748.  
  1749.   if(error=IoErr())
  1750.   {
  1751.     UBYTE errstr[91];
  1752.  
  1753.     Fault(error,MiscText[SAVE_ERROR],errstr,90);
  1754.     EZReq(Win,0,ModePro,errstr,MiscText[OK],0);
  1755.   }
  1756.   return(rv);
  1757. }    
  1758.  
  1759. void FixScreenModeNames(void)
  1760. {
  1761.   struct DefaultNode *dn;
  1762.   STRPTR newname;
  1763.  
  1764.   ObtainSemaphore(&MPSem->NodeSem);
  1765.   dn=(struct DefaultNode *)MPSem->PromotionList[PL_SCREENMODES].lh_Head;
  1766.   while(dn->Def_Node.ln_Succ)
  1767.   {
  1768. //    printf("%8lx\n",dn->OrigDisplayID);
  1769.     if(newname=GetModeName(dn->OrigDisplayID))
  1770.     {
  1771.       FreeVec(dn->Def_Node.ln_Name);
  1772.       dn->Def_Node.ln_Name=newname;
  1773.     }
  1774.     dn=(struct DefaultNode *)dn->Def_Node.ln_Succ;
  1775.   }
  1776.   ReleaseSemaphore(&MPSem->NodeSem);
  1777. }
  1778.